/**
 * 
 */
package us.gaaoc.framework.util.db;


import java.util.Iterator;
import java.util.List;

import org.apache.log4j.Logger;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import us.gaaoc.framework.dao.ModelFacade;
import us.gaaoc.framework.model.CaseRecord;

/**
 * @author artripa
 *
 */
@Component
@Configurable
public class QueryTester {

	private Logger log = Logger.getLogger(QueryTester.class);

	
	@Autowired
	SessionFactory sessionFactory;
	
	@Transactional(readOnly=true)
	public void run()
	{
		System.out.println("getting session");
		Session s = sessionFactory.getCurrentSession();

		Query q = 
			s.createQuery(
					"select distinct cr from us.gaaoc.framework.model.CaseRecord cr  join cr.caseRecordHistory chr  where (  cr.status.code = :st1 OR  cr.status.code = :st2 OR  cr.status.code = :st3 OR  cr.status.code = :st4 OR  cr.status.code = :st5 ) AND  cr.court.uuid = :courtUuid AND  cr.deletedFilingFlag = false AND  cr.clearFilingFlag = false AND cr.archivedFlag = false     order by chr.eventDateTime asc"
					);
	
		
		q = q.setString("courtUuid","courtUuidBibb")
			.setInteger("st1",2)
			.setInteger("st2",2)
			.setInteger("st3",2)
			.setInteger("st4",2)
			.setInteger("st5",2);
			
		q.list();
	}
	
	
	public static void main(String[] args)
	{
		ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
			"classpath:applicationContext-gaje2.xml");
		
		QueryTester v = (QueryTester) context.getBean("queryTester");
		v.run();
		
	}
	
	/**
	 * @param sessionFactory the sessionFactory to set
	 */
	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}
	
	
	
}
